package com.wondertek.poms.core.service.impl;

import cn.hutool.core.util.ArrayUtil;
import com.wondertek.poms.common.constant.CurrentUser;
import com.wondertek.poms.common.service.impl.ServiceImpl;
import com.wondertek.poms.common.utils.StringUtil;
import com.wondertek.poms.common.vo.GlobalCodeEnum;
import com.wondertek.poms.common.vo.ResultBean;
import com.wondertek.poms.core.config.MsgConfig;
import com.wondertek.poms.core.service.*;
import com.wondertek.poms.core.utils.DateUtil;
import com.wondertek.poms.dao.po.*;
import com.wondertek.poms.dao.pojo.ContentFeePojo;
import com.wondertek.poms.dao.pojo.PrdContSelPojo;
import com.wondertek.poms.dao.productrepo.IProductDao;
import com.wondertek.poms.dao.repo.*;
import com.wondertek.poms.dao.vo.PrdContVo;
import com.wondertek.poms.dao.vo.ProductVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.*;

/** 计费产品配置
 * @author gzx
 */
@Service
@Slf4j
@Scope("prototype")
public class ContentBaseFeeServiceImpl extends ServiceImpl<ContentBaseFee, Long> implements IContentBaseFeeService {
	@Autowired
	private IContentBaseFeeDao contentBaseFeeDao;
	@Autowired
	private IPrdContDao prdContDao;
	@Autowired
	private IEquityNodeDao equityNodeDao;
	@Autowired
	private IEquityNodeService equityNodeService;
	@Autowired
	private IPrdInfoDao prdInfoDao;
	@Autowired
	private IProductDao productDao;
	@Autowired
	private IContentDao contentDao;
	@Autowired
	private  ISellingPriceLogDao sellingPriceLogDao;
	@Autowired
	private  ISellingPriceDao sellingPriceDao;
	@Autowired
	private ISellingEquityLogDao sellingEquityLogDao;
	@Autowired
	private IProductGroupService productGroupService;
	@Autowired
	private IPrdContService prdContService;
	@Autowired
	private ISellingPriceLogService sellingPriceLogService;


	@Resource
	private MsgConfig msgConfig;
	@PersistenceContext
    public EntityManager entityManager;

	@Override
	public ContentBaseFee deleteLogic(Long id) {
		return null;
	}

	@Override
	public ContentBaseFee merge(ContentBaseFee model) {
		return null;
	}

	@Override
	public List<ContentBaseFee> queryContentBaseFee(String prdInfoId, Long prdContId) {
		return contentBaseFeeDao.findByPomsId(prdContId);
	}

	@Override
	public List<ContentBaseFee> findByPrdInfoId(Long prdInfoId) {
		return contentBaseFeeDao.findByPrdInfoId(prdInfoId);
	}

	@Override
	public List<ContentBaseFee> getJmBaseFeeByGroup(Long prdContId) {
		List<ContentBaseFee> list = new ArrayList<ContentBaseFee>();
		String sqlQuery = " select cb.channel_package_id ,cp.name, listagg(cb.EQUITY_ID,',') within GROUP (order by cb.EQUITY_ID) , listagg(cb.product_id,',') within GROUP (order by cb.product_id) " +
				"   from content_base_fee cb" +
				" left join channel_package cp on cp.id=cb.channel_package_id " +
				"  where cb.type = 2 " +
				"    and cb.poms_id = " +prdContId+
				"  group by cb.channel_package_id,cp.name 	                     ";
		Query query = entityManager.createNativeQuery(sqlQuery);
		List<Object[]> tmpList = query.getResultList();
		if(tmpList!=null && tmpList.size()>0) {
			ContentBaseFee contentBaseFee = null;
			for(Object[] obj : tmpList) {
				contentBaseFee = new ContentBaseFee();
				if(!StringUtil.isNullStr(obj[0])) {
					contentBaseFee.setChannelPackageId(StringUtil.nullToLong(obj[0]));
				}
				if(!StringUtil.isNullStr(obj[1])) {
					contentBaseFee.setChannelPackageName(StringUtil.null2Str(obj[1]));
				}
				if(!StringUtil.isNullStr(obj[2])) {
					contentBaseFee.setEquityId(StringUtil.null2Str(obj[2]));
				}
				if(!StringUtil.isNullStr(obj[3])) {
					contentBaseFee.setProductId(StringUtil.null2Str(obj[3]));
				}
				list.add(contentBaseFee);
			}
		}
		return list;
	}

	@Override
	public List<ProductVo> getProductDetail(String productIds, String equityIds, String prdContId, String channelPackage){
		if (StringUtil.isNullStr(productIds) && StringUtil.isNullStr(equityIds)) {
			return new ArrayList<ProductVo>();
		}
		PrdCont prdCont = prdContDao.findByPrdContId(StringUtil.nullToLong(prdContId));
		String sellingPrice = prdCont.getSellingPrice();
		List<ProductVo> list = new LinkedList<ProductVo>();
		if (StringUtils.isNotBlank(productIds)) {
			String[] productIDs = productIds.split(",");
			boolean falg = false;
			for (String productId : productIDs) {
				ProductVo productVo = new ProductVo();
				Product product = productDao.findByProductID(productId);
				productVo.setProductId(StringUtil.null2Str(productId));
				if(product!=null){
					productVo.setProductName(product.getName());
					productVo.setPrice(product.getPrice());
				}else {
					product=new Product();
				}
				if (falg) {
					productVo.setType("1");
				} else if (sellingPrice == null || "".equals(sellingPrice)) {
					productVo.setType("1");
				} else if (sellingPrice.equals(productId)) {
					falg = true;
					productVo.setType("0");
				} else {
					productVo.setType("1");
				}

				productVo.setChargeMode(product.getChargeMode());
				productVo.setChannelPackage(channelPackage);
				productVo.setPrdContId(prdContId);
				list.add(productVo);
			}
		}
		if (StringUtils.isNotBlank(equityIds)) {
			log.info("ContentBaseFeeServiceImpl#getProductDetail_equityIds"+equityIds);
			String[] arrayEquityIds = equityIds.split(",");
			for (String equityId : arrayEquityIds) {
				EquityNode equityNode = equityNodeService.findById(StringUtil.stringToLong(equityId));
				log.info("ContentBaseFeeServiceImpl#getProductDetail_end_equityIds"+equityIds);
				if (equityNode != null) {
					ProductVo productVo = new ProductVo();
					productVo.setEquityId(equityId);
					productVo.setEquityCode(equityNode.getEquityNodeId());
					productVo.setType("2");
					ProductGroup productGroup=null;
					if(!StringUtil.isNullStr(equityNode.getGroupId())){
						log.info("ContentBaseFeeServiceImpl#getProductDetail_groupId"+equityNode.getGroupId());
						productGroup = productGroupService.findByGroupId(equityNode.getGroupId());
						log.info("ContentBaseFeeServiceImpl#getProductDetail_end_groupId"+equityNode.getGroupId());
					}
					if (productGroup != null) {
						productVo.setGroupName(productGroup.getGroupName());
					}
					productVo.setChannelPackage(channelPackage);
					productVo.setPrdContId(prdContId);
					list.add(productVo);
				}
			}
		}
		return list;
	}

	@Override
	public List<ProductVo> getContentBaseFeeList(String prdContIds) {
		List<ProductVo> list = new LinkedList<ProductVo>();
		if (StringUtils.isNotBlank(prdContIds)) {
			String[] replaceStr = prdContIds.split(",");
			for (String prdContId : replaceStr) {
				PrdCont prdCont = prdContDao.findByPrdContId(Long.valueOf(prdContId));
				// 匹配的默认计费
				if (StringUtils.isNotBlank(prdCont.getProductId()) || StringUtils.isNotBlank(prdCont.getEquityId())) {
					ProductVo productVo=new ProductVo();
					productVo.setPrdContId(StringUtil.null2Str(prdCont.getPrdContId()));
					productVo.setContentId(StringUtil.null2Str(prdCont.getContentId()));
					productVo.setProductId(StringUtil.null2Str(prdCont.getProductId()));
					productVo.setEquityId(StringUtil.null2Str(prdCont.getEquityId()));
					productVo.setChannelPackage("");
					List<ProductVo> listDetail=getProductDetail(productVo.getProductId(), productVo.getEquityId(),  prdContId,  null);
					for (ProductVo product:listDetail) {
						//list.add(ProductVo.fromTo(productVo,product));
						list.add(product);
					}
				}
				List<ContentBaseFee> list1 = getJmBaseFeeByGroup(prdCont.getPrdContId());
				if (list1 != null && list1.size() > 0) {
					for (ContentBaseFee contentBaseFee : list1) {
						ProductVo productVo=new ProductVo();
						productVo.setPrdContId(StringUtil.null2Str(prdCont.getPrdContId()));
						productVo.setContentId(prdCont.getContentId());
						productVo.setProductId(StringUtil.null2Str(contentBaseFee.getProductId()));
						productVo.setEquityId(StringUtil.null2Str(contentBaseFee.getEquityId()));
						productVo.setChannelPackage(StringUtil.null2Str(contentBaseFee.getChannelPackageId()));
						productVo.setChannelPackageName(StringUtil.null2Str(contentBaseFee.getChannelPackageName()));
						List<ProductVo> listDetail=getProductDetail( productVo.getProductId(), productVo.getEquityId(), prdContId, productVo.getChannelPackage());
						for (ProductVo product:listDetail) {
							//list.add(ProductVo.fromTo(productVo,product));
							list.add(product);
						}
					}
				}
			}
		}
		return list;
	}

	@Transactional(rollbackFor = Exception.class)
	@Override
	public ResultBean updateProductId(ContentFeePojo contentFeePojo) {
		/**未完成优化,可参考下面的删除,整理成一次只添加一次重复调方法  */
		ResultBean resultBean=new ResultBean();
		//产品编号,权益节点,售价名称只能选一个
		int threeChoose1=0;
		String productId = contentFeePojo.getProductIds();
		String prdContId =contentFeePojo.getPrdContIds();
		String channelPackageIds =StringUtil.null2Str(contentFeePojo.getChannelInfoPackageIds());
		//渠道包不能单独选择 选择产品编号时可以选一个渠道包
		if(StringUtils.isNotBlank(channelPackageIds) && StringUtils.isBlank(productId)){
			return ResultBean.error(msgConfig.getChannelPackageIdsMustHaveProductId());
		}
		String sellingPriceId =contentFeePojo.getPriceId();
		String equityIds =contentFeePojo.getEquityIds();
		if(StringUtils.isNotBlank(productId)){
			threeChoose1+=1;
		}
		if(StringUtils.isNotBlank(sellingPriceId)){
			threeChoose1+=1;
		}
		if(StringUtils.isNotBlank(equityIds)){
			threeChoose1+=1;
		}
		if(threeChoose1!=1){
			return ResultBean.error(msgConfig.getEquityPriceProductIdOnlyOne());
		}
		boolean sellingPriceFlag = false;
		SellingPrice sellPrice=null;
		Product product=null;
		if (StringUtils.isNotBlank(sellingPriceId)) {
			sellingPriceFlag = true;
			sellPrice=sellingPriceDao.getOne(Long.parseLong(sellingPriceId));
			if(!StringUtil.isNullStr(productId) && !productId.equals(sellPrice.getProductId().toString())){
				productId = productId + "," + sellingPriceId;
			}else{
				productId = sellingPriceId;
			}
		}
		if (StringUtils.isNotBlank(channelPackageIds) && channelPackageIds.length()>0 && productId.startsWith(",")) {
			productId = productId.substring(1);
		}

		String[] prdContIds = prdContId.split(",");

		String[] channelPackageInfoIds= null;
		if(StringUtils.isNotBlank(channelPackageIds)){
			channelPackageInfoIds = channelPackageIds.split(",");
		}

		String del =StringUtil.null2Str(contentFeePojo.getDel());
		boolean result = true;
		int index = 0;
		List<ContentBaseFee> list1 = new ArrayList<ContentBaseFee>();

		String[] prodcutIds = null;
		if (!StringUtil.isNullStr(productId)) {
			prodcutIds = productId.split(",");
		}

		String[] arrayEquityIds = null;
		if (!StringUtil.isNullStr(equityIds)) {
			if (equityIds.startsWith(",")) {
				equityIds = equityIds.substring(1);
			}
			if (!StringUtil.isNullStr(equityIds)) {
				arrayEquityIds = equityIds.split(",");
				if(arrayEquityIds.length>0) {
					for (String string : arrayEquityIds) {
						long totalCount = equityNodeDao.selectCountById(StringUtil.nullToLong(string));
						if (totalCount <= 0) {
							resultBean.setMsg(msgConfig.getEquityIdError());
							resultBean.setCode(GlobalCodeEnum.FAILURE.getCode());
							return resultBean;
						}
					}
				}
			}
		}
		for (String id : prdContIds) {
			// 渠道包基本计费
			if (!StringUtil.isNullStr(channelPackageIds)) {
				for (String channelPackageId : channelPackageInfoIds) {
					if (prodcutIds != null && prodcutIds.length > 0) {
						for (String prodcutID : prodcutIds) {
							product = productDao.findByProductID(prodcutID);
							ContentBaseFee contentBaseFee = new ContentBaseFee();
							contentBaseFee.setChannelPackageId(Long.valueOf(channelPackageId));
							contentBaseFee.setPomsId(Long.valueOf(id));
							contentBaseFee.setType(2);
							contentBaseFee.setProductId(prodcutID);
							if(product!=null) {
								contentBaseFee.setPrice(product.getPrice());
								contentBaseFee.setOrderFlag(product.getChargeMode());
							}
							list1.add(contentBaseFee);
							// 记录
							PrdContSelPojo prdContSelPojo=new PrdContSelPojo();
							prdContSelPojo.setPrdContId(Long.parseLong(id));
							List<PrdContVo>  list=prdContService.findPrdContVoList(prdContSelPojo,1,1,null,null);
							PrdContVo prdContVo=new PrdContVo();
							if(ArrayUtil.isAllNotEmpty(list)){
								prdContVo=list.get(0);
							}
							String name = prdContVo.getContentName();
							String contentId = prdContVo.getContentId().toString();
							String prdInfoId = prdContVo.getPrdInfoId();
							SellingPriceLog sellingPriceLog=new SellingPriceLog();
							SellingPriceLog.putTimeAndUser(sellingPriceLog);
							sellingPriceLog.setPrdContId(id);
							sellingPriceLog.setName(name);
							sellingPriceLog.setContentId(contentId);
							sellingPriceLog.setProductId(prodcutID);
							sellingPriceLog.setOptType("1");
							sellingPriceLog.setIsSal("0");
							if(product!=null) {
								sellingPriceLog.setProductName(product.getName());
								sellingPriceLog.setPrice(product.getPrice());
							}
							sellingPriceLog.setPrdInfoId(prdInfoId);
							sellingPriceLogDao.save(sellingPriceLog);
						}
					}
					if (arrayEquityIds != null && arrayEquityIds.length > 0) {
						for (String equityId : arrayEquityIds) {
							ContentBaseFee contentBaseFee = new ContentBaseFee();
							contentBaseFee.setChannelPackageId(Long
									.valueOf(channelPackageId));
							contentBaseFee.setPomsId(Long.valueOf(id));
							contentBaseFee.setType(2);
							contentBaseFee.setEquityId(equityId);
							list1.add(contentBaseFee);
						}
					}

				}
			} else {// 节目基本计费
				PrdCont prdCont = prdContDao.findByPrdContId(Long.valueOf(prdContId.trim()));
				String jmProductId = StringUtil
						.null2Str(prdCont.getProductId());
				// 售价名称只能一个
				if (sellingPriceFlag) {
					if (!StringUtil.isNullStr(prdCont.getSellingPrice())) {
						resultBean.setCode(GlobalCodeEnum.FAILURE.getCode());
						resultBean.setMsg(msgConfig.getSellingPriceNumPrdAlreadyExist());
						return resultBean;
					}
				}
				PrdContSelPojo prdContSelPojo=new PrdContSelPojo();
				prdContSelPojo.setPrdContId(Long.parseLong(id));
				List<PrdContVo>  list=prdContService.findPrdContVoList(prdContSelPojo,1,1,null,null);
				PrdContVo prdContVo=new PrdContVo();
				if(ArrayUtil.isAllNotEmpty(list)){
					prdContVo=list.get(0);
				}
				String name = prdContVo.getContentName();
				String contentId = prdContVo.getContentId().toString();
				String prdInfoId = prdContVo.getPrdInfoId();
				if (prodcutIds != null && prodcutIds.length > 0) {
					for (String prodcutID : prodcutIds) {
						if (StringUtil.isNullStr(jmProductId)) {
							jmProductId += prodcutID;
						} else {
							jmProductId += "," + prodcutID;
						}
						SellingPriceLog sellingPriceLog=new SellingPriceLog();
						SellingPriceLog.putTimeAndUser(sellingPriceLog);
						if(sellingPriceFlag && sellPrice!=null){
							sellingPriceLog.setProductName(sellPrice.getName());
							sellingPriceLog.setPrice(sellPrice.getPrice());
						}else{
							product = productDao.findByProductID(prodcutID);
							if(product!=null){
								sellingPriceLog.setProductName(product.getName());
								sellingPriceLog.setPrice(product.getPrice());
							}
						}
						sellingPriceLog.setPrdContId(id);
						sellingPriceLog.setName(name);
						sellingPriceLog.setContentId(contentId);
						sellingPriceLog.setProductId(prodcutID);
						sellingPriceLog.setOptType("1");
						sellingPriceLog.setIsSal("0");
						sellingPriceLog.setPrdInfoId(prdInfoId);
						sellingPriceLogDao.save(sellingPriceLog);
					}
				}

				if (jmProductId != null && jmProductId.startsWith(",")) {
					jmProductId = jmProductId.substring(1);
				}
				if (arrayEquityIds != null && arrayEquityIds.length > 0) {
					String jmEquityId = StringUtil.null2Str(prdCont
							.getEquityId());
					for (String equityId : arrayEquityIds) {
						jmEquityId += "," + equityId;
					}
					if (jmEquityId != null && jmEquityId.startsWith(",")) {
						jmEquityId = jmEquityId.substring(1);
					}
					prdCont.setEquityId(jmEquityId);

					SellingEquityLog sellingEquityLog=new SellingEquityLog();
					SellingEquityLog.putTimeAndUser(sellingEquityLog);
					sellingEquityLog.setContentId(contentId);
					sellingEquityLog.setName(name);
					sellingEquityLog.setPrdContId(id);
					sellingEquityLog.setMmsId(StringUtil.null2Str(prdCont.getMmsId()));
					sellingEquityLog.setOptType("1");
					sellingEquityLog.setIsSal("0");
					for (String string : arrayEquityIds) {
						sellingEquityLog.setOperateTime(new Date());
						sellingEquityLog.setEquityId(string);
						sellingEquityLogDao.save(sellingEquityLog);
						log.info("[操作人:]"+CurrentUser.currUserName()+"给节目:"+prdContId+"添加权益id:"+string);
					}
				}
				// 节目基本计费产品ID = 手动计费产品ID + 默认计费产品ID
				prdCont.setProductId(jmProductId);
				if (sellingPriceFlag) {
					prdCont.setSellingPrice(sellingPriceId.trim());
					prdCont.setIsPersonOperation("1");
				}
				PrdInfo prdInfo = prdInfoDao.findByPrdInfoId(prdCont.getPrdInfoId());
				if ((prdInfo.getAutoVomsPublish() == 1 && prdCont.getPublishNoVOMSStatus() == null)
						|| 22!=prdCont.getPublishNoVOMSStatus()) {
					prdCont.setPublishNoVOMSStatus(PrdCont.PUBON_STATUS_NOT);// 新发布
				}
				prdContDao.save(prdCont);

			}
		}
		if (channelPackageIds != null && result == true) {
			for (ContentBaseFee contentBaseFee : list1) {
				contentBaseFeeDao.save(contentBaseFee);
				PrdCont prd = prdContDao.findByPrdContId(Long.valueOf(contentBaseFee.getPomsId()));
				PrdInfo prdInfo=prdInfoDao.findByPrdInfoId(prd.getPrdInfoId());
				if ((prdInfo.getAutoVomsPublish() == 1 && prd.getPublishNoVOMSStatus() == null)
						|| "22".equals(prd.getPublishNoVOMSStatus()) ) {
					// 新发布
					prdContDao.updatePublishNoVOMSStatus(PrdCont.PUBON_STATUS_NOT,prd.getPrdContId());
				}
			}
		}
		return ResultBean.ok();
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public ResultBean delProductId(ContentFeePojo contentFeePojo) {
		//一次只删除一个
		String equityId =contentFeePojo.getEquityIds();
		String type =contentFeePojo.getType();
		String prdContId =contentFeePojo.getPrdContId();
		String productId =contentFeePojo.getProductIds();
		String channelPackage =contentFeePojo.getChannelPackage();
		PrdCont prdCont = prdContDao.findByPrdContId(Long.parseLong(prdContId));
		if (prdCont == null) {
			return ResultBean.error("该节目不存在");
		}
		Content content=contentDao.findByContentId(prdCont.getContentId());
		// 节目售价配置记录
		SellingPriceLog sellingPriceLog = new SellingPriceLog();
		PrdInfo prdInfo=prdInfoDao.findByPrdInfoId(prdCont.getPrdInfoId());
		SellingPriceLog.putTimeAndUser(sellingPriceLog);
		sellingPriceLog.setPrdContId(String.valueOf(prdCont.getPrdContId()));
		sellingPriceLog.setOptType("0");
		sellingPriceLog.setIsSal("0");
		sellingPriceLog.setSalEndTime(prdCont.getStartTime());
		sellingPriceLog.setSalEndTime(prdCont.getEndTime());
		sellingPriceLog.setOperateTime(DateUtil.dateToString(new Date()));
		sellingPriceLog.setName(content.getName());
		sellingPriceLog.setContentId(prdCont.getContentId());
		sellingPriceLog.setPrice(prdCont.getPrice());
		sellingPriceLog.setPrdInfoId(prdInfo.getPrdInfoId().toString());

		SellingEquityLog sellingEquityLog=new SellingEquityLog();
		SellingEquityLog.putTimeAndUser(sellingEquityLog);
		sellingEquityLog.setContentId(prdCont.getContentId());
		sellingEquityLog.setName(content.getName());
		sellingEquityLog.setPrdContId(prdContId);
		sellingEquityLog.setMmsId(StringUtil.null2Str(prdCont.getMmsId()));
		sellingEquityLog.setOptType("0");
		sellingEquityLog.setIsSal("0");
		// 删除权益id先 现在权益id不能绑定渠道包
		if (!StringUtil.isNullStr(equityId)) {
			if (StringUtil.isNullStr(channelPackage)) {
				String oldEquityId = prdCont.getEquityId();
				oldEquityId = deleteStr(oldEquityId, equityId);
				sellingEquityLog.setOperateTime(new Date());
				sellingEquityLog.setEquityId(equityId);
				sellingEquityLogDao.save(sellingEquityLog);
				log.info("[操作人:]"+CurrentUser.currUserName()+"删除节目:"+prdContId+"的权益id:"+equityId);
				prdCont.setEquityId(oldEquityId);
			} else {
//				ContentBaseFee contentBaseFee=new ContentBaseFee();
//				contentBaseFee.setPomsId(Long.parseLong(prdContId));
//				contentBaseFee.setChannelPackageId(Long.parseLong(channelPackage));
//				contentBaseFee.setEquityId(equityId);
//				contentBaseFeeDao.delete(contentBaseFee);
				contentBaseFeeDao.deleteByPrdContAndChannelPackageAndEquityId(prdContId, channelPackage, equityId);
			}
		}
		// 删除产品
		if (!StringUtil.isNullStr(productId)) {
			// 1.非渠道包计费
			if (StringUtil.isNullStr(channelPackage)) {
				String oldProductId = prdCont.getProductId();
				oldProductId = deleteStr(oldProductId, productId);
				sellingPriceLog.setProductId(productId);
				sellingPriceLog.setProductName(prdInfo.getName());
				sellingPriceLogDao.save(sellingPriceLog);
				if ("0".equals(type)) {
					prdCont.setSellingPrice("");
				}
				prdCont.setProductId(oldProductId);
			} else {
//				ContentBaseFee contentBaseFee=new ContentBaseFee();
//				contentBaseFee.setPomsId(Long.parseLong(prdContId));
//				contentBaseFee.setChannelPackageId(Long.parseLong(channelPackage));
//				contentBaseFee.setProductId(productId);
//				contentBaseFeeDao.delete(contentBaseFee);
				contentBaseFeeDao.deleteByPrdContAndChannelPackageAndProductId(prdContId, channelPackage, productId);
				sellingPriceLog.setProductId(productId);
				sellingPriceLog.setProductName(prdInfo.getName());
				sellingPriceLogDao.save(sellingPriceLog);
			}
		}
		if ((prdInfo.getAutoVomsPublish() == 1 && prdCont.getPublishNoVOMSStatus() == null)
				|| "22".equals(prdCont.getPublishNoVOMSStatus()) ) {
			prdContDao.updatePublishNoVOMSStatus(PrdCont.PUBON_STATUS_NOT,prdCont.getPrdContId());
		}
		prdContDao.save(prdCont);
		return ResultBean.ok();
	}

	public String deleteStr(String ss, String s) {
		if(StringUtils.isNotBlank(ss) && StringUtils.isNotBlank(s) ){
			String s1 = ss.replace(s + ",", "");
			s1 = s1.replace("," + s, "");
			s1 = s1.replace(s, "");
			return s1;
		}else{
			return 	ss;
		}
	}

}
